package cn.xz.hibernatedemo.web.controller;

import cn.xz.hibernatedemo.ajaxRes.AjaxResult;
import cn.xz.hibernatedemo.pojo.User;
import cn.xz.hibernatedemo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @PostMapping("/insert")
    public AjaxResult saveOrUpdate(@RequestBody User user){
        userService.insert(user);
        return AjaxResult.me();
    }
    @GetMapping("/queryOne/{id}")
    public AjaxResult queryOne(@PathVariable("id") Integer id){
        return AjaxResult.me().setData(userService.queryOne(id));
    }

    @GetMapping("/queryAll")
    public AjaxResult queryAll(){
        return AjaxResult.me().setData(userService.queryAll());
    }


}
